package de.koller.hydrogen.render;

import de.koller.aframe.plain.Sprite;
import de.koller.hydrogen.HNode;
import de.koller.hydrogen.engine.player.Player;
import de.koller.hydrogen.render.textures.HTextures;
import de.koller.oceanFramework.tree.Child;
import java.awt.Graphics2D;

public class HRender extends HNode {
	
	@Child public final HTextures textures = new HTextures();
	@Child public final HCamera camera = new HCamera();
	
	public void renderThis( Graphics2D g ) {			
		camera.transform( g );
		
		renderPlayers( g );
		//renderSelected( g );
		
		camera.restore( g );
	}

	private void renderSelected( Graphics2D g ) {
		Player p = hroot.engine.selected;
		if( p == null )
			return;
		
		Sprite s = textures.selectTexture;
		s.render( g,
				p.mo.location.position.x - p.mo.size.size.x * .5f - 2,
				p.mo.location.position.y - p.mo.size.size.y * .5f - 2,
				p.mo.size.size.x + 5,
				p.mo.size.size.y + 5,
				0 );
	}
	
	private void renderPlayers( Graphics2D g ) {
		for( Player p : hroot.engine.players )
			p.render.render( g );
	}
	
}
